/**
 * 
 */
package cwinsor.com.leaf_raking;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author cwinsor
 *
 */
public class Customer {

	/*
	 * properties
	 */
	RakerColumns myDay;
	StartTime myStartTime;
	Shift myShift;

	Team myTeam;

	String town;
	String name;
	String phone;
	String address;
	String sizeOfArea;
	String notes;
	String email;

	/*
	 * debug
	 */
	private int debugSection = 1;
	String dM = this.getClass().getSimpleName() + "----";
	String dF = this.getClass().getSimpleName() + "---- ERROR ---- ";

	/*
	 * addData
	 * take in raw data, check, and internalize
	 */
	public void addData(ArrayList<String> theFieldsObject) {

		// basics
		town = theFieldsObject.get(2);
		name = theFieldsObject.get(6);
		phone = theFieldsObject.get(7);
		address = theFieldsObject.get(8);


		// BHRA-specified Team will be in the Notes - otherwise UNASSIGNED
		if (theFieldsObject.size() > 10) {
			myTeam = Team.stringContainsTeam(theFieldsObject.get(10).toString(),false);
		} else {
			myTeam = Team.TEAM_UNASSIGNED;
		}

		// if there is a BHRA-specified Day and StartTime in the Notes - that takes precedence
		if (theFieldsObject.size() > 10) {
			myDay = RakerColumns.stringContainsDay(theFieldsObject.get(10).toString(), false);
			myStartTime = StartTime.stringContainsStartTime(theFieldsObject.get(10).toString(), false);

			// but there has to be BOTH, otherwise it is an error
			if  (   ((myDay == null) && (myStartTime != null)) ||
					((myDay != null) && (myStartTime == null))) {
				System.out.println(dF + "when reading .csv file the NOTE for "
						+ theFieldsObject.get(6).toString()
						+ " specified one (but not both) of Day and StartTime. Need both");
				System.exit(1);
				return;
			}
			// BHRA did not specifiy Day or StartTime, so use the one from SuperSAAS
			if  ((myDay == null) && (myStartTime == null)) {
				myDay = RakerColumns.stringContainsDay(theFieldsObject.get(0).toString());
				myStartTime = StartTime.stringContainsStartTime(theFieldsObject.get(0).toString());
			} else {
				// note to user that BHRA date/time was used instead of that in SuperSAAS
				System.out.println(dM + "OVERRIDING DATE/TIME FOR CUSTOMER "
						+ name.toString()
						+ " !!!!!!!!!");
			}

			// a final check on this topic - make sure Day and StartTime got assigned
			if  ((myDay == null) || (myStartTime == null)) {
				System.out.println(dF + "either Day or Start did not get assigned");
				System.exit(1);
				return;
			}

			myShift = Shift.startTimeToShift(myStartTime);

			if (theFieldsObject.size() > 9) {
				sizeOfArea = theFieldsObject.get(9);
			} else {
				sizeOfArea = "";
			}

			if (theFieldsObject.size() > 10) {
				notes = theFieldsObject.get(10).toString();
			} else {
				notes = "";
			}
			if (theFieldsObject.size() > 11) {
				email = theFieldsObject.get(11).toString();
			} else {
				email = "";
			}
		}
	}


	/**
	 * getters
	 */
	RakerColumns getDay() {
		return myDay;
	}
	StartTime getStartTime() {
		return myStartTime;
	}
	Shift getShift() {
		return myShift;
	}

	Team getTeam() {
		return myTeam;
	}

	String getTown() {
		return town;
	}
	String getName() {
		return name;
	}
	String getPhone() {
		return phone;
	}
	String getAddress() {
		return address;
	}
	String getSizeOfArea() {
		return sizeOfArea;
	}
	String getNotes() {
		return notes;
	}
	String getEmail() {
		return email;
	}


	/*
	 * toStringCommaDelimited
	 * return fields as a comma-delimited string
	 */
	public String toStringCommaDelimitedAllFields() {
		String s = new String();

		s = getDay()
				+ "," + getStartTime().toString()
				+ "," + getShift().toString()
				+ "," + getTeam().toString()
				+ "," + getTown().toString()
				+ "," + getName().toString()
				+ "," + getPhone().toString()
				+ "," + getAddress().toString()
				+ "," + getSizeOfArea().toString()
				+ "," + getNotes().toString();
		return s;
	}
}
